Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Windows.Forms

Public Class FrmCrTonCongNo_KhachHang
    Private thang, nam, makh, tenkh As String
    Private customerReport As ReportDocument
    Private reportPath As String
    Private flagInHoaDon As Integer = 0

    Private Sub FrmCrTonCongNo_KhachHang_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If makh = "ALL" Then ' then
            frmLoading.Show()
            Dim sqlQuery As String
            sqlQuery = " SELECT t1.*,t2.ten_nhacungcap as ten_khachhang ,t3.ma_nhom_khachhang as nhom,t3.ten_nhom_khachhang as tennhom "
            sqlQuery += " FROM  ( tbl_dot_toncongno_khachhang as t1 left join tbl_khachhang as t2 on t1.ma_khachhang=t2.ma_nhacungcap) "
            sqlQuery += " left join tbl_nhom_khachhang as t3 on t2.ma_nhom=t3.ma_nhom_khachhang "
            sqlQuery += " where recycleID='" & nam & thang & "' AND (thanhtien_dauky <> 0 OR phatsinhno_trongky <> 0 "
            sqlQuery += " OR thanhtoan_trongky <> 0 OR thanhtien_cuoiky <> 0)ORDER BY t2.ten_nhacungcap "
            If flagInHoaDon = 0 Then
                reportPath = Application.StartupPath & "\" & "CrTonCongNoKhachHang_nhom.rpt"
            End If

            If flagInHoaDon = 1 Then
                reportPath = Application.StartupPath & "\" & "CrTonCongNoKhachHang_nhom_ketoan.rpt"
            End If
            customerReport = New ReportDocument()
            customerReport.Load(reportPath)
            customerReport.SetDataSource(moduleReportConfig.GetDataTable(sqlQuery))
            customerReport.SetParameterValue("TThang", thang)
            customerReport.SetParameterValue("TNam", nam)
            customerReport.SetParameterValue("TMakh", makh)
            customerReport.SetParameterValue("TTenkh", tenkh)
            customerReport.SetParameterValue("company", globalVariale.COMPANY)
            customerReport.SetParameterValue("address", globalVariale.ADDRESS)
            Me.CrNXTTongHopview.ReportSource = customerReport
            frmLoading.Close()
            frmLoading.Dispose()
        Else
            frmLoading.Show()
            Dim sqlQuery As String
            sqlQuery = " SELECT t1.*,t2.ten_nhacungcap as ten_khachhang  "
            sqlQuery += " FROM ( tbl_dot_toncongno_khachhang as t1 left join tbl_khachhang as t2 on t1.ma_khachhang=t2.ma_nhacungcap ) "
            '  sqlQuery += " left join tbl_nhom_khachhang as t3 on t2.ma_nhom=t3.ma_nhom_khachhang "
            sqlQuery += " Where  t2.ma_nhom= '" & makh & "' AND recycleID='" & nam & thang & "' AND (thanhtien_dauky <> 0 OR phatsinhno_trongky <> 0 OR thanhtoan_trongky <> 0 OR thanhtien_cuoiky <> 0)ORDER BY t2.ten_nhacungcap "
            'sqlQuery += " Where  recycleID='" & nam & thang & "' AND (thanhtien_dauky <> 0 OR phatsinhno_trongky <> 0 OR thanhtoan_trongky <> 0 OR thanhtien_cuoiky <> 0)ORDER BY t2.ten_nhacungcap "
            If flagInHoaDon = 0 Then
                reportPath = Application.StartupPath & "\" & "CrTonCongNoKhachHang.rpt"
            Else
                reportPath = Application.StartupPath & "\" & "CrTonCongNoKhachHang_ketoan.rpt"
            End If
            customerReport = New ReportDocument()
            customerReport.Load(reportPath)
            customerReport.SetDataSource(moduleReportConfig.GetDataTable(sqlQuery))
            customerReport.SetParameterValue("TThang", thang)
            customerReport.SetParameterValue("TNam", nam)
            customerReport.SetParameterValue("TMakh", makh)
            customerReport.SetParameterValue("TTenkh", tenkh)
            customerReport.SetParameterValue("company", globalVariale.COMPANY)
            customerReport.SetParameterValue("address", globalVariale.ADDRESS)
            Me.CrNXTTongHopview.ReportSource = customerReport
            frmLoading.Close()
            frmLoading.Dispose()
        End If
    End Sub

    Public Sub setThang(ByVal s As String)
        thang = s
    End Sub

    Public Sub setNam(ByVal s As String)
        nam = s
    End Sub

    Public Sub setMakh(ByVal s As String)
        makh = s
    End Sub
    Public Sub setTenkh(ByVal s As String)
        tenkh = s
    End Sub
    Public Sub setInHoaDon(ByVal s As Integer)
        Me.flagInHoaDon = s
    End Sub
End Class
